package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;

import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.AdminService;

import com.tarena.lbs.pojo.basic.param.AdminParam;
import com.tarena.lbs.pojo.basic.query.AdminQuery;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;



@RestController
@Slf4j
public class AdminController {
    @Autowired
    private AdminService adminService;
    //后台登录用例 admin账号详情查询
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail() throws BusinessException {
        //怎么调用业务 查询当前发起请求的登陆者信息
        //请求头携带了jwt Authorization 包含userPrinciple id nickname roles
        //String jwt = request.getHeader("Authorization");
        //log.info("当前头携带的jwt:{}",jwt);
        AdminVO vo=adminService.detail();
        return new Result<>(vo);
    }
    //后台账号列表分页查询
    @PostMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> adminPage(@RequestBody AdminQuery query)
            throws BusinessException{
        PageResult<AdminVO> voPages=adminService.adminPage(query);
        return new Result<>(voPages);
    }
    //后台新增账号
    @PostMapping("/admin/basic/role/add")
    public Result<Void> adminSave(@RequestBody AdminParam param)
            throws BusinessException{
        adminService.adminSave(param);
        return Result.success();
    }

}
